package com.glory.dgcpcpda.adapter;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.glory.dgcpcpda.R;
import com.glory.dgcpcpda.activity.mfg.MaterielDownActivity;
import com.glory.dgcpcpda.activity.mfg.MaterielUpActivity;
import com.glory.dgcpcpda.entity.MaterielListEntity;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_Utils;

import java.util.List;

/**
 * FileName: ReplacrMaterialListAdapter
 * Author: XJH
 * Date: 2020/9/3 11:02
 * Description:
 * History:
 */
public class ReplaceMaterialListAdapter extends BaseQuickAdapter<MaterielListEntity.Materiel, BaseViewHolder> {

    private boolean isStart = true;
    private String mEqp = "";
    private String mlotId="";

    public ReplaceMaterialListAdapter(@Nullable List<MaterielListEntity.Materiel> data) {
        super(R.layout.item_bin_info_list,data);
    }

    public void setStart(boolean b){
        this.isStart = b;
    }

    public void setEqpID(String eqpID){
        this.mEqp = eqpID;
    }

    public void setMlotId(String mlotID){this.mlotId=mlotID;}

    @Override
    protected void convert(BaseViewHolder helper, MaterielListEntity.Materiel item) {
        String materialType=item.getPOSITIONNAME()==null?"":item.getPOSITIONNAME();
        String name;
        if("RLF".equals(materialType)){
            name="框架";
        }else if("REP".equals(materialType)){
            name="装片胶";
        }else if("REP0".equals(materialType)){
            item.setPOSITIONNAME("REP");
            name="装片胶1";
        }else if("REP1".equals(materialType)){
            item.setPOSITIONNAME("REP");
            name="装片胶2";
        }else if("WAFER".equals(materialType)){
            name="芯片";
        }else{
            name=materialType;
        }
        //helper.setText(R.id.list_tv1,item.getPOSITIONNAME());原语句
        helper.setText(R.id.list_tv1,name);//新语句
        helper.setText(R.id.list_tv2,item.getMLOT().getMATERIALNAME());
        helper.setText(R.id.list_tv3,item.getMLOT().getMLOTID());
        helper.setGone(R.id.list_tv4,true);
        helper.setText(R.id.list_tv4,item.getMLOT().getMATERIALNAME().equals("") ? "上机" : "下机");

        TextView mView = helper.getView(R.id.list_tv4);
        mView.setOnClickListener(view -> {
            if (!isStart){
                Bundle bundle = new Bundle();
                bundle.putString("EQPID",mEqp);
                bundle.putString("POSITION",item.getPOSITIONNAME());
                bundle.putString("MLOTID",item.getMLOT().getMLOTID());
                FreeApi_Utils.skipWithExtraIntent("header",bundle,mContext,mView.getText().toString().equals("上机") ? MaterielUpActivity.class : MaterielDownActivity.class);
            }
        });
    }
}
